package com.yh.autobio.modules.adatper;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yh.autobio.R;
import com.yh.autobio.common.StringUtils;
import com.yh.autobio.modules.bean.View_MY_SaleBill;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * @author imyar
 *
 * @date 2015年12月2日
 */
public class SaleBillAdapter extends ListBaseAdapter<View_MY_SaleBill> {

    static class ViewHolder {
        @InjectView(R.id.tv_ywy)
        TextView tv_ywy;
        @InjectView(R.id.tv_customername1)
        TextView  tv_customername1;
        @InjectView(R.id.tv_customername2)
        TextView  tv_customername2;
        @InjectView(R.id.tv_customername3)
        TextView  tv_customername3;
        @InjectView(R.id.tv_customername4)
        TextView   tv_customername4;
        @InjectView(R.id.tv_customername)
        TextView tv_customername;
        @InjectView(R.id.tv_time)
        TextView time;
        @InjectView(R.id.tv_title)
        TextView title;
        @InjectView(R.id.tv_description)
        TextView description;
        @InjectView(R.id.iv_statue)
        ImageView iv_statue;
        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
    String type;
    public  SaleBillAdapter(String type){
        this.type=type;
    }

    @Override
    protected View getRealView(final int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.list_cell_news, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        if ("CK".equals(type)) {
            vh.tv_customername.setVisibility(View.GONE);
            vh.tv_customername1.setVisibility(View.GONE);
            vh.tv_customername2.setVisibility(View.VISIBLE);
            vh.tv_customername3.setVisibility(View.GONE);
            View_MY_SaleBill blog = mDatas.get(position);
            vh.title.setText("单号："+blog.getFBillNo());
            vh.tv_customername.setText("购货单位："+blog.getDepartmentName());
            vh.tv_customername1.setText("产品名称："+blog.getProutName());
            vh.tv_customername2.setText("数量："+blog.getExpr1());
            vh.tv_customername3.setText("出料仓库："+blog.getLibName());
            vh.tv_customername4.setText("总金额："+blog.getAllMoney()+"元");
            String note = blog.getFNote();
            if (StringUtils.isEmpty(note)) {
                vh.description.setVisibility(View.GONE);
            } else {
                vh.description.setText(note);
            }
            vh.tv_ywy.setText("操作人："+blog.getFWorkerName());
            String time = blog.getFDate();
            if (!StringUtils.isEmpty(time)) {
                if (time.indexOf(".") > -1) {
                    vh.time.setText(time.replace("T", " ").substring(0, time.indexOf(".")));
                } else {
                    vh.time.setText(time.replace("T", " "));
                }
            }
        }else if ("RK".equals(type)){
            vh.tv_customername.setVisibility(View.GONE);
            vh.tv_customername1.setVisibility(View.GONE);
            vh.tv_customername2.setVisibility(View.VISIBLE);
            vh.tv_customername3.setVisibility(View.GONE);

            View_MY_SaleBill blog = mDatas.get(position);
            vh.title.setText("单号："+blog.getFBillNo());
            vh.tv_customername.setText("交货单位："+blog.getDepartmentName());
            vh.tv_customername1.setText("产品名称："+blog.getProutName());
            vh.tv_customername2.setText("数量："+blog.getExpr1());
            vh.tv_customername3.setText("收货仓库："+blog.getLibName());
            String note = blog.getFNote();
            if (StringUtils.isEmpty(note)) {
                vh.description.setVisibility(View.GONE);
            } else {
                vh.description.setText(note);
            }
            vh.tv_ywy.setText("操作人："+blog.getFWorkerName());
            String time = blog.getFDate();
            if (!StringUtils.isEmpty(time)) {
                if (time.indexOf(".") > -1) {
                    vh.time.setText(time.replace("T", " ").substring(0, time.indexOf(".")));
                } else {
                    vh.time.setText(time.replace("T", " "));
                }
            }
        }
        return convertView;
    }
}
